﻿using System.CommandLine;
using System.CommandLine.IO;
using System.Text;
using System.Windows;

namespace WholeSlideImageViewer
{
    internal class MessageBoxConsole : IConsole, IStandardStreamWriter
    {
        public IStandardStreamWriter Out => this;

        public bool IsOutputRedirected => true;

        public IStandardStreamWriter Error => this;

        public bool IsErrorRedirected => true;

        public bool IsInputRedirected => true;

        private StringBuilder? _builder;

        public void Write(string value)
        {
            if (_builder is null)
            {
                _builder = new StringBuilder();
            }
            _builder.Append(value);
        }

        public bool TryShow()
        {
            if (_builder is null)
            {
                return false;
            }
            else
            {
                MessageBox.Show(_builder.ToString());
                _builder.Clear();
                _builder = null;
                return true;
            }
        }
    }
}
